//package com.sc.nft.service.impl;
//
//import com.meta.component.base.api.CommonResult;
//import com.meta.user.client.api.UserBindThirdClient;
//import com.meta.user.client.req.UserBindThirdReq;
//import com.meta.user.client.res.UserBindThirdRes;
//import com.sc.nft.entity.WxMiniUserInfo;
//import com.sc.nft.service.WxMiniUserService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeanUtils;
//import org.springframework.lang.NonNull;
//import org.springframework.stereotype.Service;
//
///**
// * (ActivityAward)表服务实现类
// *
// * @author 王伟成
// * @since 2023-09-13 15:34:01
// */
//@Slf4j
//@Service
//@RequiredArgsConstructor
//public class WxMiniUserServiceImpl implements WxMiniUserService {
//
//    private final UserBindThirdClient userBindThirdClient;
//
//    @Override
//    public WxMiniUserInfo findByParam(@NonNull Param param) {
//        // 使用远程接口兼容旧逻辑
//        UserBindThirdReq req = new UserBindThirdReq();
//        BeanUtils.copyProperties(param, req);
//        CommonResult<UserBindThirdRes> result = userBindThirdClient.findByParam(req);
//        WxMiniUserInfo info = new WxMiniUserInfo();
//        BeanUtils.copyProperties(result.getData(), info);
//        return info;
//    }
//
//    //    private final WxMiniUserInfoDao wxMiniUserInfoDao;
////    private final UserInfoService userInfoService;
////    private final WxMiniLogInClient wxMiniLogInClient;
////    private final StringRedisTemplate redisTemplate;
////    private final UserInfoService userInfoService;
////    private final MallUserWalletService mallUserWalletService;
////    private final WxMiniUserPointsClient wxMiniUserPointsClient;
////
////    @Override
////    public GetUserOpenIdVO login(WxCodeReq request) throws GlobalException {
////        GetUserOpenIdVO getUserOpenIdVO = wxMiniLogInClient.getOpenId(request);
////        Assert.isFalse(getUserOpenIdVO == null || StringUtils.isEmpty(getUserOpenIdVO.getOpenId()),()-> new GlobalException("请稍后重试"));
////        WxMiniUserInfo wxMiniUserInfo = wxMiniUserInfoDao.getByOpenId(getUserOpenIdVO.getOpenId());
////        if (wxMiniUserInfo == null) {
////            return getUserOpenIdVO;
////        }
////        miniUserLogin(getUserOpenIdVO.getOpenId(),wxMiniUserInfo.getId());
////        getUserOpenIdVO.setIsHave(Boolean.TRUE);
////        return getUserOpenIdVO;
////    }
////
////    @Override
////    @Transactional(rollbackFor = Exception.class)
////    public String register(WxCodeReq request) throws GlobalException {
////        GetUserMobileNumberVO mobileNumber = wxMiniLogInClient.getMobileNumber(request);
////        Assert.isFalse((mobileNumber == null || StringUtils.isEmpty(mobileNumber.getMobileNumber())),()-> new GlobalException("请稍后重试"));
////        UserInfo userInfo = userInfoDao.getOneByUserTel(mobileNumber.getMobileNumber());
////        Long miniUserId = 0L;
////        if (userInfo != null) {
////            //用户在玛特注册过
////            //判断是否有用户了但是没有绑定openId
////            WxMiniUserInfo checkWxMiniUserInfo = wxMiniUserInfoDao.getByUserId(userInfo.getId());
////            if (Objects.nonNull(checkWxMiniUserInfo) && StringUtils.isEmpty(checkWxMiniUserInfo.getOpenId())) {
////                checkWxMiniUserInfo.setOpenId(request.getOpenId());
////                Assert.isTrue(wxMiniUserInfoDao.updateOpenId(checkWxMiniUserInfo),()-> new GlobalException("请稍后重试"));
////                miniUserId = checkWxMiniUserInfo.getId();
////            }else if (Objects.isNull(checkWxMiniUserInfo)){
////                //判断用户是否换了手机号重新换绑一下玛特id
////                WxMiniUserInfo checkUseTelWxMiniUserInfo = wxMiniUserInfoDao.getByUseTel(userInfo.getUserTel());
////                if (Objects.nonNull(checkUseTelWxMiniUserInfo)) {
////                    checkUseTelWxMiniUserInfo.setUserId(userInfo.getId());
////                    Assert.isTrue(wxMiniUserInfoDao.updateUserId(checkUseTelWxMiniUserInfo),()-> new GlobalException("请稍后重试"));
////                    miniUserId = checkUseTelWxMiniUserInfo.getId();
////                } else {
////                    WxMiniUserInfo wxMiniUserInfo = WxMiniUserInfo.build(mobileNumber.getMobileNumber(),userInfo.getId(),request.getOpenId());
////                    Assert.isTrue(wxMiniUserInfoDao.save(wxMiniUserInfo),()-> new GlobalException("请稍后重试"));
////                    miniUserId = wxMiniUserInfo.getId();
////                }
////            }else {
////                miniUserId = checkWxMiniUserInfo.getId();
////            }
////        } else {
////            //没在玛特注册过注册玛特账号
////            UserLoginVO userLoginVO = userInfoService.registeUser("", 1, mobileNumber.getMobileNumber(), "");
////            Assert.isTrue(userLoginVO != null && userLoginVO.getUserId() != null,()-> new GlobalException("请稍后重试"));
////            WxMiniUserInfo wxMiniUserInfo = WxMiniUserInfo.build(mobileNumber.getMobileNumber(),userLoginVO.getUserId(),request.getOpenId());
////            Assert.isTrue(wxMiniUserInfoDao.save(wxMiniUserInfo),()-> new GlobalException("请稍后重试"));
////            miniUserId = wxMiniUserInfo.getId();
////        }
////        //初始化钱包
////        Assert.isTrue(mallUserWalletService.initWallet(miniUserId),()-> new GlobalException("请稍后重试"));
////        Assert.isTrue(wxMiniUserPointsClient.initUserPoint(InitUserPointsReq.build(miniUserId)),()-> new GlobalException("请稍后重试"));
////        miniUserLogin(request.getOpenId(),miniUserId);
////        return request.getOpenId();
////    }
////
////    private void miniUserLogin(String openId,Long miniUserId){
////        redisTemplate.opsForValue().set(openId,String.valueOf(miniUserId));
////    }
////
////    @Override
////    public void miniUserLogOut(WxMiniUserInfo wxMiniUser){
////        if (Objects.isNull(wxMiniUser) || StringUtils.isEmpty(wxMiniUser.getOpenId())){
////            return;
////        }
////        redisTemplate.delete(wxMiniUser.getOpenId());
////    }
////
////    @Override
////    public String getAccessToken() {
////        return wxMiniLogInClient.getAccessToken();
////    }
//}
